package com.cnswhy.cloud.server.core.service.impl;


import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.server.common.entity.enumeration.SplitType;
import com.cnswhy.cloud.server.core.dao.CustomerSplitMapper;
import com.cnswhy.cloud.server.core.entity.Customer;
import com.cnswhy.cloud.server.core.entity.CustomerSplit;
import com.cnswhy.cloud.server.core.service.CustomerSplitService;
import com.cnswhy.cloud.common.core.base.service.SuperServiceImpl;

import com.cnswhy.cloud.server.core.service.customer.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 业务实现类
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2021-03-02
 */
@Slf4j
@Service

public class CustomerSplitServiceImpl extends SuperServiceImpl<CustomerSplitMapper, CustomerSplit> implements CustomerSplitService {
    @Autowired
    CustomerService customerService;
    @Override
    public List<CustomerSplit>  getVerifyList(Long customerId, String status, SplitType splitType) {
        log.info("getVerifyList:{} {} {}", customerId,status,splitType.getDesc());
        List<CustomerSplit> customerSplitSet = baseMapper.selectList(Wraps.<CustomerSplit>lbQ().eq(CustomerSplit::getCustomerId, customerId).eq(CustomerSplit::getStatus, status).eq(CustomerSplit::getSplitType,splitType));
        for(CustomerSplit customerSplit : customerSplitSet){
            Customer customer = customerService.getById(customerSplit.getDownCustomerId());
            if("1".equals(customer.getVerifyStatus())){
                customerSplit.setVerifyFlag("已实名");
            }else{
                customerSplit.setVerifyFlag("未实名");
            }
            String likeString = customer.getPromoterList();

            List<Customer> customerList = customerService.list(Wraps.<Customer>lbQ().ne(Customer::getId, customerSplit.getDownCustomerId()).eq(Customer::getPromoterId, customerSplit.getDownCustomerId()));
            customerSplit.setDownCount(customerList.size());
            customerList = customerService.list(Wraps.<Customer>lbQ().ne(Customer::getId, customerSplit.getDownCustomerId()).ne(Customer::getPromoterId, customerSplit.getDownCustomerId()).likeRight(Customer::getPromoterList, likeString));
            customerSplit.setDownDownCount(customerList.size());

        }
        return customerSplitSet;

    }
}
